package com.yc.bran.snack.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yc.bran.snack.bean.AdminInfo;
import com.yc.bran.snack.enums.ResultEnmu;
import com.yc.bran.snack.service.IAdminInfoService;
import com.yc.bran.snack.util.ConstantInfo;
import com.yc.bran.snack.vo.ResultVo;
@Controller
@RequestMapping("/admin")
public class AdminInfoController {
	@Autowired
	private IAdminInfoService adminInfoService;
	
	@PostMapping("/login")
	@ResponseBody
	public ResultVo login(HttpSession session, AdminInfo af) {
		AdminInfo admin = adminInfoService.login(af);
		if(admin == null) {
			return new ResultVo(ResultEnmu.ERROR);
		}
		session.setAttribute(ConstantInfo.LOGINADMININFO, admin);
		return new ResultVo(ResultEnmu.SUCCESS);
	}
	
	@GetMapping("/check")
	@ResponseBody
	public ResultVo check(HttpSession session) {
		Object obj = session.getAttribute(ConstantInfo.LOGINADMININFO);
		if(obj == null) {
			return new ResultVo(ResultEnmu.ERROR);
		}
		return new ResultVo(ResultEnmu.SUCCESS, obj);
	}
}
